package com.google.code.whitetask.old;

import static com.google.code.whitetask.old.TryCatchDecorator.*;

public class TaskExpression {
  public static Task task(Task task) {
    return task;
  }

  public static Task failover(Task task) {
    return task;
  }

  public static int retryCount(int retryCount) {
    return retryCount;
  }

  public static TaskResultType expected(TaskResultType expected) {
    return expected;
  }

  public static Task afterTask(Task task) {
    return task;
  }

  public static Task mainTask(Task task) {
    return task;
  }

  public static Task beforeTask(Task task) {
    return task;
  }

  public static TaskEvent event(TaskEvent event) {
    return event;
  }

  public static AsyncerDecorator asyncer(Task task, TaskEvent event) {
    return new AsyncerDecorator(task).event(event);
  }

  public static AsyncerDecorator asyncer(Task task) {
    return asyncer(task, null);
  }

  public static boolean loggable(boolean loggable) {
    return loggable;
  }

  public static boolean throwable(boolean throwable) {
    return throwable;
  }

  public static TaskResultType resultWhenFailed(TaskResultType resultType) {
    return resultType;
  }

  public static TaskProxy proxy(TaskProxy proxy) {
    return proxy;
  }

  public static TryCatchDecorator tryCatch(Task task, boolean loggable,
      boolean throwable, TaskResultType willReturn) {
    return new TryCatchDecorator(task).loggable(loggable).throwable(throwable)
        .willReturn(willReturn);
  }

  public static TryCatchDecorator tryCatch(Task task, boolean loggable) {
    return tryCatch(task, loggable, DEFAULT_THROWABLE,
        DEFAULT_RESULT_WHEN_FAILED);
  }

  public static TryCatchDecorator throwableTryCatch(Task task, boolean loggable) {
    return tryCatch(task, loggable, true, DEFAULT_RESULT_WHEN_FAILED);
  }

  public static TryCatchDecorator tryCatch(Task task,
      TaskResultType resultWhenFailed) {
    return tryCatch(task, DEFAULT_LOGGABLE, DEFAULT_THROWABLE, resultWhenFailed);
  }

  public static TryCatchDecorator throwableTryCatch(Task task,
      TaskResultType resultWhenFailed) {
    return tryCatch(task, DEFAULT_LOGGABLE, true, resultWhenFailed);
  }

  public static TaskChain chain(Task... tasks) {
    TaskChain result = new TaskChain();
    for (Task each : tasks) {
      result.add(each);
    }
    return result;
  }

  public static TaskChain chain(TaskProxy proxy, Task... tasks) {
    return chain(tasks).proxy(proxy);
  }

  public static Times times(int times) {
    return new Times(times);
  }
}
